﻿/**********************************************************************
 * @file   FITKRadiossSolverSettings.h
 * @brief  Radioss 求解设置
 * @author liuzhonghua (liuzhonghuaszch@163.com)
 * @date   2025-09-05
 *********************************************************************/
#ifndef __FITKRADIOSSSOLVERSETTINGS_H__
#define __FITKRADIOSSSOLVERSETTINGS_H__

#include "FITKRadiossDataAPI.h"
#include "FITK_Kernel/FITKCore/FITKAbstractDataObject.h"

namespace Radioss
{
    /**
     * @brief  求解运行时间参数
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2025-09-08
     */
    class FITKRadiossDataAPI FITKRadiossSolverRunExeTimeParam : public QObject
    {
    public:
        explicit FITKRadiossSolverRunExeTimeParam() = default;
        /**
         * @brief    设置运行最终时间
         * @param[i] time 
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        void setFinalTime(const double time);
        /**
         * @brief    获取运行最终时间
         * @return   double
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        double getFinalTime() const;

    private:
        /**
         * @brief  最终时间
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2025-09-05
         */
        double _finalTime{ 0.001 };
    };
    /**
     * @brief  求解全局时间参数
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2025-09-08
     */
    class FITKRadiossDataAPI FITKRadiossSolverGlobalTimeParam : public QObject
    {
    public:
        explicit FITKRadiossSolverGlobalTimeParam() = default;
        /**
         * @brief    设置启用最小时间步长
         * @param[i] state
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        void setEnableMinTimeStep(const bool state);
        /**
         * @brief    是否启用最小时间步长
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        bool isEnableMinTimeStep() const;
        /**
         * @brief    设置最小时间步长
         * @param[i] time
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        void setMinTimeStep(const double time);
        /**
         * @brief    获取最小时间步长
         * @return   double
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        double getMinTimeStep() const;
        /**
         * @brief    设置启用时间停止的缩放因子
         * @param[i] state
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        void setEnableScaleFactor(const bool state);
        /**
         * @brief    是否启用时间停止的缩放因子
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        bool isEnableScaleFactor() const;
        /**
         * @brief    设置时间停止的缩放因子
         * @param[i] s
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        void setScaleFactor(const double s);
        /**
         * @brief    获取时间停止的缩放因子
         * @return   double
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        double getScaleFactor() const;

    private:
        /**
         * @brief  是否启用最小时间步长
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2025-09-08
         */
        bool _isEnableMinTimeStep{ false };
        /**
         * @brief  最小时间步长
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2025-09-08
         */
        double _minTimeStep{ 0.0 };
        /**
         * @brief  是否启用时间停止的缩放因子
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2025-09-05
         */
        bool _isEnableScaleFactor{ false };
        /**
         * @brief  时间停止的缩放因子
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2025-09-08
         */
        double _scaleFactor{ 0.9 };
    };
    /**
     * @brief  求解节点时间步长控制参数
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2025-09-08
     */
    class FITKRadiossDataAPI FITKRadiossSolverNodalTimeStepControlParam : public QObject
    {
        Q_OBJECT
    public:
        /**
         * @brief  时间步控制类型
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2025-09-08
         */
        enum NodalTimeStepControlType
        {
            NodalTimeStep_SolverDefault,
            NodalTimeStep_CST,
            NodalTimeStep_SET,
            NodalTimeStep_STOP,
        };
        Q_ENUM(NodalTimeStepControlType);

    public:
        explicit FITKRadiossSolverNodalTimeStepControlParam() = default;

        void setTimeStepControlType(const NodalTimeStepControlType type);
        NodalTimeStepControlType getTimeStepControlType() const;

        void setMinimumTimeStep(const double time);
        double getMinimumTimeStep() const;

        void setScaleFactor(const double s);
        double getScaleFactor() const;

        void setInitialAddMassRatio(const double r);
        double getInitialAddMassRatio() const;

    private:
        NodalTimeStepControlType _controlType{ NodalTimeStepControlType::NodalTimeStep_SolverDefault };
        double _minTimeStep{ 0 };
        double _scaleFactor{ 0 };
        double _initAddMassRatio{ 0 };
    };
    /**
     * @brief  求解单元时间步长控制参数
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2025-09-08
     */
    class FITKRadiossDataAPI FITKRadiossSolverElementalTimeStepControlParam : public QObject
    {
        Q_OBJECT
    public:
        /**
         * @brief  时间步控制类型
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2025-09-08
         */
        enum ElementalTimeStepControlType
        {
            ElementalTimeStep_SolverDefault,
            ElementalTimeStep_CST,
            ElementalTimeStep_DEL,
            ElementalTimeStep_STOP,
        };
        Q_ENUM(ElementalTimeStepControlType);

    public:
        explicit FITKRadiossSolverElementalTimeStepControlParam() = default;
        
        void setTimeStepControlType(const ElementalTimeStepControlType type);
        ElementalTimeStepControlType getTimeStepControlType() const;

        void setMinimumTimeStep(const double time);
        double getMinimumTimeStep() const;

        void setScaleFactor(const double s);
        double getScaleFactor() const;

        void setNumberOfAddCards(const bool addCards);
        bool getNumberOfAddCards() const;

        void setMinAspectRatio(const double value);
        double getMinAspectRatio() const;

        void setMinVolumeRatio(const double value);
        double getMinVolumeRatio() const;

    private:
        ElementalTimeStepControlType _controlType{ ElementalTimeStepControlType::ElementalTimeStep_SolverDefault };
        double _minTimeStep{ 0 };
        double _scaleFactor{ 0 };
        bool _numberOfAddCards{ true };
        double _minAspectRatio{ 0.2 };
        double _minVolumeRatio{ 0.05 };
    };
    /**
     * @brief  求解自适应动态松弛
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2025-09-08
     */
    class FITKRadiossDataAPI FITKRadiossSolverAdaptiveDynamicRelaxation : public QObject
    {
    public:
        explicit FITKRadiossSolverAdaptiveDynamicRelaxation() = default;
        
        void setEnableDynamicRelaxation(const bool isEnable);
        bool getEnableDynamicRelaxation() const;

        void setEnableStartTime(const bool isEnable);
        bool isEnableStartTime() const;

        void setStartTime(const double time);
        double getStartTime() const;

        void setEnableStopTime(const bool isEnable);
        bool isEnableStopTime() const;

        void setStopTime(const double time);
        double getStopTime() const;

    private:
        bool _enableDynamicRelaxation{ false };
        bool _enableStartTime{ false };
        double _startTime{ 0.0 };
        bool _enableStopTime{ false };
        double _stopTime{ 0.0 };
    };
    /**
     * @brief  求解AMS单元时间步长控制参数
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2025-09-08
     */
    class FITKRadiossDataAPI FITKRadiossSolverAMSElementalTimeStepControlParam : public QObject
    {
    public:
        explicit FITKRadiossSolverAMSElementalTimeStepControlParam() = default;

        void setEnableCriticalTimeStepScaleFactor(const bool isEnable);
        bool isEnableCriticalTimeStepScaleFactor() const;

        void setCriticalTimeStepScaleFactor(const double value);
        double getCriticalTimeStepScaleFactor() const;

        void setEnableMinTimeStep(const bool isEnable);
        bool isEnableMinTimeStep() const;

        void setMinTimeStep(const double value);
        double getMinTimeStep() const;

        void setEnableAMSConvergenceTolerance(const bool isEnable);
        bool isEnableAMSConvergenceTolerance() const;

        void setAMSConvergenceTolerance(const double value);
        double getAMSConvergenceTolerance() const;

        void setEnableMaxIterationsConjugateGradient(const bool isEnable);
        bool isEnableMaxIterationsConjugateGradient() const;

        void setMaxIterationsConjugateGradient(const double value);
        double getMaxIterationsConjugateGradient() const;

        void setEnableNumberOfAdditionalOutputs(const bool isEnable);
        bool isEnableNumberOfAdditionalOutputs() const;

        void setNumberOfAdditionalOutputs(const double value);
        double getNumberOfAdditionalOutputs() const;

    private:
        bool _isEnableCriticalTimeStepScaleFactor{ false };
        double _criticalTimeStepScaleFactor{ 0.9 };
        bool _isEnableMinTimeStep{ false };
        double _minTimeStep{ 0.0 };
        bool _isEnableAMSConvergenceTolerance{ false };
        double _AMSConvergenceTolerance{ 0.0001 };
        bool _isEnableMaxIterationsConjugateGradient{ false };
        double _maxIterationsConjugateGradient{ 1000 };
        bool _isEnableNumberOfAdditionalOutputs{ false };
        double _numberOfAdditionalOutputs{ 0.0 };
    };

    /**
     * @brief  求解计算控制参数
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2025-09-08
     */
    class FITKRadiossDataAPI FITKRadiossSolverComputationControlParam : public QObject
    {
    public:
        explicit FITKRadiossSolverComputationControlParam() = default;
        
        void setStopComputationWhenNegativeVolume(const bool isStop);
        bool getStopComputationWhenNegativeVolume() const;

        void setParallelArithmetic(const bool isParallel);
        bool getParallelArithmetic() const;

    private:
        bool _stopComputationWhenNegativeVolume{ true };
        bool _parallelArithmetic{ true };
    };
    /**
     * @brief  求解收敛标准参数
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2025-09-08
     */
    class FITKRadiossDataAPI FITKRadiossSolverConvergenceCriteriaParam : public QObject
    {
    public:
        explicit FITKRadiossSolverConvergenceCriteriaParam() = default;

        void setStopComputation(const bool state);
        bool getStopComputation() const;

        void setEnergyErrorRatio(const double value);
        double getEnergyErrorRatio() const;

        void setTotalMassRatio(const double value);
        double getTotalMassRatio() const;

        void setNodalMassRatio(const double value);
        double getNodalMassRatio() const;

        void setWriteTimeHistoryFile(const bool state);
        bool getWriteTimeHistoryFile() const;

        void setWriteAnimationFile(const bool state);
        bool getWriteAnimationFile() const;

        void setEnergyError(const bool state);
        bool getEnergyError() const;

    private:
        bool _stopComputation{ true };
        double _energyErrorRatio{ 0.99 };
        double _totalMassRatio{ 0.05 };
        double _nodalMassRatio{ 0.0 };
        bool _writeTimeHistoryFile{ true };
        bool _writeAnimationFile{ true };
        bool _energyError{ true };
    };
    /**
     * @brief  Radioss 求解设置
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2025-09-05
     */
    class FITKRadiossDataAPI FITKRadiossSolverSettings : public Core::FITKAbstractDataObject
    {
    public:
        /**
         * @brief 构造函数
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2025-09-05
         */
        explicit FITKRadiossSolverSettings();
        
        /**
         * @brief 析构函数
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2025-09-05
         */
        virtual ~FITKRadiossSolverSettings();
        /**
         * @brief    获取运行时时间参数
         * @return   FITKRadiossSolverRunExeTimeParam *
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        FITKRadiossSolverRunExeTimeParam* getRunExeTimeParam();
        /**
         * @brief    获取全局时间参数
         * @return   FITKRadiossSolverGlobalTimeParam *
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        FITKRadiossSolverGlobalTimeParam* getGlobalTimeParam();
        /**
         * @brief    获取节点时间步长控制参数
         * @return   FITKRadiossSolverNodalTimeStepControlParam *
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        FITKRadiossSolverNodalTimeStepControlParam* getNodalTimeStepControlParam();
        /**
         * @brief    获取单元时间步长控制参数
         * @return   FITKRadiossSolverElementalTimeStepControlParam *
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        FITKRadiossSolverElementalTimeStepControlParam* getElementalTimeStepControlParam();
        /**
         * @brief    获取自适应动态松弛
         * @return   FITKRadiossSolverAdaptiveDynamicRelaxation *
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        FITKRadiossSolverAdaptiveDynamicRelaxation* getAdaptiveDynamicRelaxation();
        /**
         * @brief    获取AMS单元时间步长控制参数
         * @return   FITKRadiossSolverAMSElementalTimeStepControlParam *
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        FITKRadiossSolverAMSElementalTimeStepControlParam* getAMSElementalTimeStepControlParam();
        /**
         * @brief    获取计算控制参数
         * @return   FITKRadiossSolverComputationControlParam *
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        FITKRadiossSolverComputationControlParam* getComputationControlParam();
        /**
         * @brief    获取收敛标准参数
         * @return   FITKRadiossSolverConvergenceCriteriaParam *
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-09-08
         */
        FITKRadiossSolverConvergenceCriteriaParam* getConvergenceCriteriaParam();


    private:
        FITKRadiossSolverRunExeTimeParam* _runExeTimeParam{ nullptr };
        FITKRadiossSolverGlobalTimeParam* _globalTimeParam{ nullptr };
        FITKRadiossSolverNodalTimeStepControlParam* _nodalTimeStepControlParam{ nullptr };
        FITKRadiossSolverElementalTimeStepControlParam* _elementalTimeStepControlParam{ nullptr };
        FITKRadiossSolverAdaptiveDynamicRelaxation* _adaptiveDynamicRelaxation{ nullptr };
        FITKRadiossSolverAMSElementalTimeStepControlParam* _AMSElementalTimeStepControlParam{ nullptr };
        FITKRadiossSolverComputationControlParam* _computationControlParam{ nullptr };
        FITKRadiossSolverConvergenceCriteriaParam* _convergenceCriteriaParam{ nullptr };

    };


} // namespace Radioss

#endif // __FITKRADIOSSSOLVERSETTINGS_H__